package com.example.superoa.model.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.dao.BecomeWorkerDao;
import com.example.superoa.model.dao.ContractDao;
import com.example.superoa.model.dao.DepartmentDao;
import com.example.superoa.model.dao.EntryDao;
import com.example.superoa.model.dao.PositionDao;
import com.example.superoa.model.dao.StaffDao;
import com.example.superoa.model.mappers.ContractMapper;
import com.example.superoa.model.mappers.DepartmentMapper;
import com.example.superoa.model.mappers.EntryMapper;
import com.example.superoa.model.mappers.StaffMapper;
import com.example.superoa.model.pojos.BecomeWorker;
import com.example.superoa.model.pojos.Contract;
import com.example.superoa.model.pojos.Department;
import com.example.superoa.model.pojos.Entry;
import com.example.superoa.model.pojos.Jobchage;
import com.example.superoa.model.pojos.Position;
import com.example.superoa.model.pojos.Staff;
import com.example.superoa.model.vo.EntryVo;
import com.example.superoa.model.vo.StaffVo;

@Service
@Transactional(rollbackFor=Exception.class)
public class StaffService {
	@Autowired
	private StaffMapper stamapper;
	
	@Autowired
	private StaffDao staffdao;
	
	@Autowired
	private DepartmentMapper dmpaer;
	
	@Autowired
	private EntryMapper entrymapper;
	
	@Autowired
	private ContractMapper contractmapper;
	
	@Autowired
	private EntryDao entrydao;
	
	@Autowired
	private ContractDao condao;
	
	@Autowired
	private PositionDao p_dao;
	
	@Autowired
	private BecomeWorkerDao bedao;
	//查询合同表所有
	public List<StaffVo> staffAll(){
		return stamapper.staffAll();
	}
	//获取编辑数据
	public Staff staffById(int staff_id) {
		return stamapper.staffById(staff_id);
	}
	/*修改员工信息*/
	public void staffedit(Staff ss) {
		System.out.println("ss==="+ss);
		Staff s=stamapper.staffById(ss.getStaffId());
		s.setStaff_name(ss.getStaff_name());
		s.setStaff_sex(ss.getStaff_sex());
		s.setStaff_Political(ss.getStaff_Political());
		s.setStaffYears(ss.getStaffYears());
		staffdao.findById(ss.getStaffId()).get();
		System.out.println(ss.getStaffId());
		System.err.println("s===="+s);
	}
	
	/*条件查询*/
	public JSONArray staffselect(String staff_name) {
		JSONArray array =stamapper.staffselect(staff_name);
		return array;
	}
	//多表添加、转正表、员工表
	public void adddbtj(Staff e,Contract cnm,Entry en,BecomeWorker be,Department d,Integer position_id,Position p,Jobchage j) {
		Position position=p_dao.findById(position_id).get();
		List<Staff> list=position.getStaffs();
		if(list==null) {
			list=new ArrayList();
		}
		list.add(e);
		condao.save(cnm);
		staffdao.save(e);
		entrydao.save(en);
		bedao.save(be);
		p_dao.save(position);
	}
	public Department finddepartById(String depart_name) {
		return dmpaer.adepartmentId(depart_name);
	}
	public Contract conselectId(String Contract_TypeName) {
		return contractmapper.conselectId(Contract_TypeName);
	}
	
	//审核入职信息
	public void ruzhiState(String Entystate,int Entryid) {
		entrymapper.ruzhiState(Entystate, Entryid);
	}
	public void xiugaizt(String Staff_sfzz,int staff_id) {
		System.out.println("staff-id=="+staff_id);
		stamapper.staffstae(Staff_sfzz, staff_id);
	}
	//查询入职信息
	public EntryVo entryAll(int entryid) {
		return entrymapper.entryId(entryid);
	}
	//查询员工信息
	public void selectaaa(Staff staffId) {
		//return staffdao.save(entity)
	}
}
